<template>
  <div class="nav-bar">
    <div class="nav-content">
      <div class="logo">
        <h1>AI表情包生成器</h1>
      </div>
      <nav class="nav-menu">
        <router-link to="/" class="nav-item">首页</router-link>
        <router-link to="/generate" class="nav-item">生成表情包</router-link>
        <router-link to="/batch" class="nav-item">批量生成</router-link>
        <router-link to="/history" class="nav-item">历史记录</router-link>
      </nav>
      <div class="user-info" v-if="username">
        <el-dropdown>
          <span class="user-dropdown">
            {{ username }}
            <el-icon><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>
                <router-link to="/profile">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item divided @click="handleLogout">
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Picture,
  List,
  User,
  Setting,
  ChatDotRound,
  SwitchButton,
  ArrowDown
} from '@element-plus/icons-vue'

const router = useRouter()
const username = ref(localStorage.getItem('username'))

const handleLogout = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('userId')
  localStorage.removeItem('username')
  ElMessage.success('已退出登录')
  router.push('/login')
}
</script>

<style scoped>
.nav-bar {
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--primary-color);
}

.nav-menu {
  display: flex;
  gap: 20px;
}

.nav-item {
  text-decoration: none;
  color: var(--text-color);
  padding: 8px 12px;
  border-radius: 4px;
  transition: all 0.3s;
}

.nav-item:hover,
.nav-item.router-link-active {
  color: var(--primary-color);
  background-color: rgba(64, 158, 255, 0.1);
}

.user-info {
  cursor: pointer;
}

.user-dropdown {
  display: flex;
  align-items: center;
  gap: 4px;
}

.el-dropdown-menu {
  padding: 5px 0;
}

.el-dropdown-menu a {
  text-decoration: none;
  color: inherit;
}
</style> 